//
//  LeiListViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/5/17.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "LeiListViewController.h"
#import "DiseaseProductTableViewCell.h"
#import "ProductDetailViewController.h"

@interface LeiListViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *leiListTableView; // 类列表

@end

@implementation LeiListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    // 布局
    [self addMySubview];
}

// navi的修改
- (void)changeNavigation
{
    [self.navigationController.navigationBar setTranslucent:NO];
    
    // 左边
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    UIBarButtonItem *leftFirstItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    
    
    self.navigationItem.leftBarButtonItem = leftFirstItem;
    
    self.navigationItem.title = @"产品内容";
    
    
    
    
}

#pragma mark - 返回
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 布局
- (void)addMySubview
{
    self.leiListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
    self.leiListTableView.backgroundColor = [UIColor whiteColor];
    self.leiListTableView.dataSource = self;
    self.leiListTableView.delegate = self;
    [self.view addSubview:_leiListTableView];
}

#pragma mark - 代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.leiListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"searchLeiCell";
    DiseaseProductTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[DiseaseProductTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (self.leiListArray.count > indexPath.row) {
        cell.model = self.leiListArray[indexPath.row];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProductDetailViewController *leiDetailVC = [[ProductDetailViewController alloc] init];
    if (self.leiListArray.count > indexPath.row) {
        SearchProductPackageModel *model = self.leiListArray[indexPath.row];
        leiDetailVC.leiIDString = [NSString stringWithFormat:@"%@", model.classID];
    }
    [self.navigationController pushViewController:leiDetailVC animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 107 * kAdjustParamater;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
